package spring.cloud.tasks.api.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import spring.cloud.tasks.api.service.TaskService;
import spring.cloud.tasks.api.utils.Response;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Execution status for specified job.
 */
@RequestMapping("/console/namespaces/{namespace:.+}/jobs/{jobName}/execution")
public class JobExecutionController {

    @Resource
    private TaskService jobService;

    /**
     * 获取作业执行状态
     */
    //@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
    @GetMapping(value = "/getExecutionStatus")
    public Response getExecutionStatus(final HttpServletRequest request, @PathVariable String namespace,
                                       @PathVariable String jobName) throws RuntimeException {
        return Response.success(jobService.getExecutionStatus(namespace, jobName));
    }

    //@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
    @GetMapping(value = "/getExecutionLog")
    public Response getExecutionLog(final HttpServletRequest request, @PathVariable String namespace,
                                    @PathVariable String jobName, @RequestParam String jobItem) throws RuntimeException {
        return Response.success(jobService.getExecutionLog(namespace, jobName, jobItem));
    }
}
